package com.xps.charmingshop.servicer;


import com.xps.charmingshop.view.activity.RegisterActivity;

import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.InputStreamBody;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;

import java.io.InputStream;
import java.util.Map;


/**
 * Created by liwenhan on 2017/11/14.
 */

public class UserServiceImpl implements UserService {


    @Override
    public String userUpload(InputStream in, Map<String, String> data, String set)
            throws Exception {
        HttpClient client = new DefaultHttpClient();
        HttpPost post = new HttpPost("http://www.meitianpaotui.com/api/upload_image/image_upload");
        //要把数据封装到post里面去
        /*Httpmine*/
        MultipartEntity entity = new MultipartEntity();
        //二进制的流文件数据对象
        entity.addPart("avatar", new InputStreamBody(in, "image/jpg", set));
        //数据放到post
        post.setEntity(entity);
        HttpResponse response = client.execute(post);
        int statusCode = response.getStatusLine().getStatusCode();
        System.out.println(statusCode);
        if (statusCode != HttpStatus.SC_OK) {

        }
        String result = EntityUtils.toString(response.getEntity(), HTTP.UTF_8);
        return result;
    }

}